home *** CD-ROM | disk | FTP | other *** search
- package sheet;
-
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- import javax.microedition.lcdui.TextBox;
-
- final class Cell {
- static final String[] colors = new String[]{"White", "Light Gray", "Black"};
- static final int BG_WHITE = 0;
- static final int BG_LGRAY = 1;
- static final int BG_BLACK = 2;
- static final String[] aligns = new String[]{"Default", "Right", "Center", "Left"};
- static final int AL_DEFAULT = 0;
- static final int AL_RIGHT = 1;
- static final int AL_CENTER = 2;
- static final int AL_LEFT = 3;
- private static CellContainer parent;
- private static Calculate calc = new Calculate((1)null);
- private byte column;
- private byte row;
- private short colorIdx = 0;
- private short alignIdx = 0;
- private String formula;
- private Operand result;
- private boolean calculated;
- private String errMsg;
- private Image image;
-
- public Cell(CellContainer var1, byte var2, byte var3) {
- parent = var1;
- this.column = var2;
- this.row = var3;
- this.calculated = true;
- this.render();
- }
-
- public boolean isData() {
- return this.colorIdx != 0 || this.formula != null;
- }
-
- public byte getRow() {
- return this.row;
- }
-
- public byte getColumn() {
- return this.column;
- }
-
- public void setColor(short var1) {
- if (this.colorIdx != var1) {
- this.colorIdx = var1;
- parent.notifyChanged();
- this.render();
- }
-
- }
-
- public void setAlign(short var1) {
- if (this.alignIdx != var1) {
- this.alignIdx = var1;
- parent.notifyChanged();
- this.render();
- }
-
- }
-
- public void render() {
- if (this.isData()) {
- short var1 = parent.getColumnWidth(this.column);
- short var2 = parent.getRowHeight(this.row);
- Font var3 = Font.getFont(64, 0, 8);
- int var4 = var2 - var3.getHeight();
- int var5 = 1;
- String var6 = this.errMsg == null ? (this.result == null ? "" : Operand.getText(this.result)) : this.errMsg;
- int var7 = var3.stringWidth(var6);
- if (var7 > 0) {
- int var8 = var1 - 3;
- int var9 = this.alignIdx;
- if (var7 > var8) {
- var7 = var8;
- }
-
- if (var9 == 0) {
- var9 = this.result != null && Operand.isNumber(this.result) ? 1 : 3;
- }
-
- switch (var9) {
- case 1:
- var5 = var8 - var7;
- break;
- case 2:
- var5 = (var8 - var7) / 2;
- break;
- case 3:
- var5 = 1;
- }
- }
-
- this.image = Image.createImage(var1, var2);
- Graphics var12 = this.image.getGraphics();
- var12.setColor(0);
- var12.setFont(var3);
- switch (this.colorIdx) {
- case 1:
- int var13 = 1 - var1 % 2;
-
- for(int var10 = 1; var10 < var2; var10 += 2) {
- var12.drawLine(0, var10, var2 - 1 - var10, var2 - 1);
- var12.drawLine(var1 - 1, var10 - var13, var1 - 1 - var10 + var13, 0);
- }
-
- for(int var11 = 1; var11 <= var1 - var2; var11 += 2) {
- var12.drawLine(var11, 0, var11 + var2 - 1, var2 - 1);
- }
-
- var12.setColor(16777215);
- var12.drawString(var6, var5 + 1, var4 + 1, 20);
- var12.setColor(0);
- break;
- case 2:
- var12.fillRect(0, 0, var1, var2);
- var12.setColor(16777215);
- }
-
- var12.drawString(var6, var5, var4, 20);
- } else {
- this.image = null;
- }
-
- }
-
- public int paint(Graphics var1, int var2, int var3) {
- if (this.image != null) {
- var1.drawImage(this.image, var2, var3, 20);
- }
-
- return this.colorIdx == 2 ? 16777215 : 0;
- }
-
- public String getName() {
- char var1 = (char)(65 + this.column);
- return var1 + String.valueOf(this.row + 1);
- }
-
- public String getDetails() {
- StringBuffer var1 = new StringBuffer();
- if (this.formula != null) {
- var1.append("Formula: ");
- var1.append(this.formula);
- var1.append("\n");
- if (this.errMsg != null) {
- var1.append("Error: ");
- var1.append(this.errMsg);
- } else if (this.result != null) {
- var1.append("Result: ");
- var1.append(Operand.getText(this.result));
- } else {
- var1.append("No result");
- }
- }
-
- return var1.toString();
- }
-
- public void notCalculated() {
- this.result = null;
- this.calculated = false;
- }
-
- public boolean isCalculated() {
- return this.calculated;
- }
-
- public void paste(Cell var1) {
- if (var1 != null) {
- this.formula = var1.formula;
- this.colorIdx = var1.colorIdx;
- this.alignIdx = var1.alignIdx;
- parent.notifyChanged();
- parent.calculate();
- }
-
- }
-
- public boolean calculate() {
- this.calculated = true;
- this.errMsg = null;
- if (this.formula != null) {
- CellCalc var1 = new CellCalc(calc);
- char var2 = this.formula.charAt(0);
- if (var2 == '=' && this.formula.length() > 1) {
- try {
- this.result = var1.calculate(this.formula, (short)1, (short)this.formula.length());
- } catch (IllegalArgumentException var4) {
- this.calculated = false;
- this.result = null;
- this.errMsg = ((Throwable)var4).getMessage();
- }
- } else if (var2 == '\'') {
- this.result = new Operand(this.formula.substring(1), false);
- } else {
- this.result = new Operand(this.formula, true);
- }
- }
-
- this.render();
- return this.calculated;
- }
-
- public void edit(String var1, Backable var2, Display var3) {
- byte var4 = 0;
- if (var1 == null) {
- var1 = this.formula;
- } else if (var1.length() > 0 && Character.isDigit(var1.charAt(0))) {
- var4 = 2;
- }
-
- String var5 = this.getName();
- Command var6 = new Command("Ok", 4, 0);
- Command var7 = new Command("Cancel", 3, 0);
- Command var8 = new Command("Help", 5, 0);
- TextBox var9 = new TextBox(var5, var1, 50, var4);
- ((Displayable)var9).setCommandListener(new 1(this, var8, var3, var6, var2));
- ((Displayable)var9).addCommand(var6);
- ((Displayable)var9).addCommand(var7);
- ((Displayable)var9).addCommand(var8);
- var3.setCurrent(var9);
- }
-
- public boolean appendChar(char var1, boolean var2) {
- if (var1 == '\b' && this.formula != null) {
- int var3 = this.formula.length();
- if (var3 > 1) {
- this.formula = this.formula.substring(0, var3 - 1);
- } else {
- this.formula = null;
- }
- } else if (!var2 && this.formula != null) {
- this.formula = this.formula + var1;
- } else {
- this.formula = String.valueOf(var1);
- }
-
- parent.notifyChanged();
- parent.calculate();
- return this.formula != null && this.formula.length() != 0;
- }
-
- public byte[] serialize(int var1) {
- byte[] var2;
- if (this.isData() && var1 == 1) {
- byte[] var3 = this.formula == null ? new byte[0] : this.formula.getBytes();
- var2 = new byte[var3.length + 4];
- var2[0] = this.column;
- var2[1] = this.row;
- var2[2] = (byte)this.colorIdx;
- var2[3] = (byte)this.alignIdx;
- System.arraycopy(var3, 0, var2, 4, var3.length);
- } else {
- var2 = null;
- }
-
- return var2;
- }
-
- public static Cell deserialize(byte[] var0, CellContainer var1, int var2) {
- Cell var3;
- if (var2 == 1 && var0 != null) {
- var3 = new Cell(var1, var0[0], var0[1]);
- var3.colorIdx = (short)var0[2];
- var3.alignIdx = (short)var0[3];
- var3.formula = new String(var0, 4, var0.length - 4);
- if (var3.formula.length() == 0) {
- var3.formula = null;
- }
-
- var3.calculated = false;
- } else {
- var3 = null;
- }
-
- return var3;
- }
-
- static CellContainer access$000() {
- return parent;
- }
-
- static String access$100(Cell var0) {
- return var0.errMsg;
- }
-
- static boolean access$200(Cell var0) {
- return var0.calculated;
- }
-
- static Operand access$300(Cell var0) {
- return var0.result;
- }
-
- static Calculate access$500() {
- return calc;
- }
-
- static String access$600(Cell var0) {
- return var0.formula;
- }
-
- static String access$602(Cell var0, String var1) {
- return var0.formula = var1;
- }
-
- static String access$102(Cell var0, String var1) {
- return var0.errMsg = var1;
- }
- }
-